package com.laowang.project.system.service.impl;

import java.util.List;

import com.laowang.common.exception.CustomException;
import com.laowang.project.system.domain.MyCyhVipAuthority;
import com.laowang.project.system.service.MyCyhVipAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.laowang.project.system.mapper.MyCyhAuthorityMapper;
import com.laowang.project.system.domain.MyCyhAuthority;
import com.laowang.project.system.service.MyCyhAuthorityService;

import javax.swing.undo.CannotUndoException;

/**
 * 会员权益Service业务层处理
 *
 * @author laowang
 * @date 2023-06-01
 */
@Service
public class MyCyhAuthorityServiceImpl implements MyCyhAuthorityService {
    @Autowired
    private MyCyhAuthorityMapper myCyhAuthorityMapper;

    @Autowired
    private MyCyhVipAuthorityService myCyhVipAuthorityService;
    /**
     * 查询会员权益
     *
     * @param id 会员权益ID
     * @return 会员权益
     */
    @Override
    public MyCyhAuthority selectMyCyhAuthorityById(Integer id) {
        return myCyhAuthorityMapper.selectMyCyhAuthorityById(id);
    }

    /**
     * 查询会员权益列表
     *
     * @param myCyhAuthority 会员权益
     * @return 会员权益
     */
    @Override
    public List<MyCyhAuthority> selectMyCyhAuthorityList(MyCyhAuthority myCyhAuthority) {
        return myCyhAuthorityMapper.selectMyCyhAuthorityList(myCyhAuthority);
    }

    /**
     * 新增会员权益
     *
     * @param myCyhAuthority 会员权益
     * @return 结果
     */
    @Override
    public int insertMyCyhAuthority(MyCyhAuthority myCyhAuthority) {
        return myCyhAuthorityMapper.insertMyCyhAuthority(myCyhAuthority);
    }

    /**
     * 修改会员权益
     *
     * @param myCyhAuthority 会员权益
     * @return 结果
     */
    @Override
    public int updateMyCyhAuthority(MyCyhAuthority myCyhAuthority) {
        return myCyhAuthorityMapper.updateMyCyhAuthority(myCyhAuthority);
    }

    /**
     * 批量删除会员权益
     *
     * @param ids 需要删除的会员权益ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhAuthorityByIds(Integer[] ids) {
        for (Integer id : ids) {
            MyCyhVipAuthority myCyhVipAuthority = new MyCyhVipAuthority();
            myCyhVipAuthority.setAuthorityId(id);
            List<MyCyhVipAuthority> myCyhVipAuthorities = myCyhVipAuthorityService.selectMyCyhVipAuthorityList(myCyhVipAuthority);
            if (myCyhVipAuthorities.size()>0){
                throw new CustomException("不能删除此会员介绍,关联到会员权益",400);
            }
        }
        return myCyhAuthorityMapper.deleteMyCyhAuthorityByIds(ids);
    }

    /**
     * 删除会员权益信息
     *
     * @param id 会员权益ID
     * @return 结果
     */
    @Override
    public int deleteMyCyhAuthorityById(Integer id) {
        return myCyhAuthorityMapper.deleteMyCyhAuthorityById(id);
    }
}
